#include "queue.h"

#include "exceptions.h"

using namespace pita;

unsigned int Queue::size() const
{
	return source_descriptors_.size();
}

SourceDescriptor Queue::sourceDescriptor(Index idx) const
{
	if (idx < size())
		return source_descriptors_[idx];

	throw IndexError();
}

void Queue::insert(const SourceDescriptor& sd, Index idx)
{
	idx = idx < size() ? idx : size();
	
	SourceDescriptors::iterator itr = source_descriptors_.begin() + idx;
	source_descriptors_.insert(itr, sd);
	
	insertSignal(idx);
}

void Queue::erase(Index idx)
{
	if (idx >= size()) return;

	SourceDescriptors::iterator itr = source_descriptors_.begin() + idx;
	assert(itr != source_descriptors_.end());

	source_descriptors_.erase(itr);

	eraseSignal(idx);
}
